﻿using DataService.Core.Common;
using DataService.Core.HttpClientHelper;
using DataService.Core.Json;
using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Text;

namespace UnitTest.HttpClient
{
    public class RequestUploadFileDTO
    {
        /// <summary>
        /// 文件流对应随机数,可使用 Guid.NewGuid() 或其他随机值
        /// 例Dic["XXXX"]=byte[],则 Random=XXXX
        /// </summary>
        public string Random { get; set; }

        /// <summary>
        ///  文件名称(含后缀)
        /// </summary>
        public string FileName { get; set; }

        /// <summary>
        /// 客户端选择的物理文件全路径
        /// </summary>
        // public string FileFullPath { get; set; }
        #region 其它业务逻辑属性

        #endregion

    }
    public class TestHttpClient
    {
        private string url = string.Empty;

        public void TestUploadFile()
        {

            url = "http://localhost:5206/API/Login/LoginUser";
            string tempResult = HttpClientHelper.HttpRequestHelper("", url, null, null);
            HandleResult handleResult = JsonHelper.ToJsonEntity<HandleResult>(tempResult);
            string token = handleResult.Result.ToString();

            Dictionary<string, byte[]> fileDic = new Dictionary<string, byte[]>();
            Dictionary<string, string> paraDic = new Dictionary<string, string>();
            List<string> imgPaths = new List<string>();
            imgPaths.Add(@"C:\Users\dell\Pictures\Camera Roll\0d88f7714ccd9e3c80976de076df9234.jpeg");
            imgPaths.Add(@"C:\Users\dell\Pictures\Camera Roll\2a49cd90614eed49b463b1ca80b877f7.jpg");
            imgPaths.Add(@"C:\Users\dell\Pictures\Camera Roll\4fd2f8d00540cc83f5d829c4a873f639.jpg");
            List<RequestUploadFileDTO> requestFileDTOs = new List<RequestUploadFileDTO>();
            foreach (string item in imgPaths)
            {
                string random = Guid.NewGuid().ToString().Replace("-", "");

                var tempModel = new RequestUploadFileDTO
                {
                    Random = random,
                    // FileFullPath = item,
                    FileName = Path.GetFileName(item),

                };
                requestFileDTOs.Add(tempModel);
                fileDic[random] = FileHelper.ReadFile(item);

                string tempStr = tempModel.ToJson();
                paraDic[random] = tempStr;

            }
            url = "http://localhost:5106/API/Files/MultipleUploadFile";

             tempResult = HttpClientHelper.HttpMultipleFileRequestHelper(token, url, fileDic, paraDic, null);
            Console.WriteLine(tempResult);


        }


        public void TestJWT()
        {
            url = "http://localhost:5206/API/Login/LoginUser";
            string tempResult = HttpClientHelper.HttpRequestHelper("",url, null,null);
            HandleResult handleResult= JsonHelper.ToJsonEntity<HandleResult>(tempResult);
            string token = handleResult.Result.ToString();

            url = "http://localhost:5206/API/Login/TestJWT";
            tempResult= HttpClientHelper.HttpRequestHelper(token, url, null, null);
            Console.WriteLine(tempResult);
        }

    }
}
